//
//  ViewController.m
//  AVAudioPlayerDemo
//
//  Created by Lucky on 15/10/7.
//  Copyright © 2015年 Lucky. All rights reserved.
//

#import "ViewController.h"

#import "JKRMusicTool.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIButton *playButton;

@property (nonatomic, strong) NSArray *musics;

@property (nonatomic, assign) int currentIndex;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (NSArray *)musics
{
    if (!_musics) {
        _musics = @[@"南拳妈妈 - 下雨天.mp3", @"杨丞琳 - 雨爱.mp3", @"方雅贤 - 遇到.mp3"];
    }
    return _musics;
}

- (IBAction)play:(UIButton *)sender {
    sender.selected = !sender.selected;
    sender.selected ? [JKRMusicTool playMusicWithFileName:self.musics[self.currentIndex]]:[JKRMusicTool pauseMusicWithFileName:self.musics[self.currentIndex]];
}

- (IBAction)next:(UIButton *)sender {
    int nextIndex = self.currentIndex + 1;
    if (nextIndex >= self.musics.count) {
        nextIndex = 0;
    }
    [self stop:nil];
    self.currentIndex = nextIndex;
    self.playButton.selected = NO;
    [self play:self.playButton];
}

- (IBAction)stop:(UIButton *)sender {
    self.playButton.selected = NO;
    [JKRMusicTool stopMusicWithFileName:self.musics[self.currentIndex]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
